import Vue from 'vue'
export default {
  add(state, obj) {
    Vue.set(obj, "id", state.id);
    state.list.push(obj);
    state.id = state.list.length;
    localStorage.setItem("list", JSON.stringify(state.list));
    localStorage.setItem("id", state.id);
  },
  // 改变状态
  change(state, obj) {
    state.list.forEach(elem => {
      if (elem.id == obj.id) {
        elem.isTrue = obj.check;
        return;
      }
    });
    localStorage.setItem("list", JSON.stringify(state.list));
  },
  // 删除
  del(state, id) {
    // console.log(state.list)
    state.list.forEach((elem, index, arr) => {
      if (elem.id == id) {
        arr.splice(index, 1);
        return;
      }
    });
    localStorage.setItem("list", JSON.stringify(state.list));
    localStorage.setItem("id", state.list.length);
    if (state.list.length == 0) {
      localStorage.removeItem('id');
      state.id = 0
    }
  }
}
